 
<!--微信用户首页-->  

<link rel="stylesheet" type="text/css" href="__STATIC__/weixin/assets/sell/baseui/css/amazeui.css"/>
<link rel="stylesheet" type="text/css" href="__STATIC__/weixin/assets/sell/baseui/css/admin.css"/>
<link rel="stylesheet" type="text/css" href="__STATIC__/weixin/assets/sell/css/style.css"/>




<!--[if (gte IE 9)|!(IE)]><!-->
	<script type="text/javascript" src="//cdn.bootcss.com/jquery/2.2.2/jquery.min.js"></script>
	<script type="text/javascript" src="//cdn.bootcss.com/fastclick/1.0.6/fastclick.min.js"></script>
  	<script>$(function() {FastClick.attach(document.body);});</script>
<!--<![endif]-->

<!--[if lte IE 8 ]>
	<script type="text/javascript" src="http://libs.baidu.com/jquery/1.11.3/jquery.min.js"></script>
	<script type="text/javascript" src="http://cdn.staticfile.org/modernizr/2.8.3/modernizr.js"></script>
	<script type="text/javascript" src="__STATIC__/weixin/assets/sell/baseui/js/amazeui.ie8polyfill.min.js"></script>
<![endif]-->

<script type="text/javascript" src="//cdn.bootcss.com/amazeui/2.7.2/js/amazeui.min.js"></script>
<link rel="stylesheet" href="__STATIC__/weixin/assets/sell/css/user.css">

<div class="am-modal am-modal-alert" tabindex="-1" id="fq_alert">
  <div class="am-modal-dialog">
    <div class="am-modal-hd" id="fq_alert_title"></div>
    <div class="am-modal-bd" id="fq_alert_info">
    </div>
    <div class="am-modal-footer">
      <span class="am-modal-btn">确定</span>
    </div>
  </div>
</div>

<div class="am-modal am-modal-confirm" tabindex="-1" id="fq_confirm">
  <div class="am-modal-dialog">
    <div class="am-modal-hd" id="fq_confirm_title"></div>
    <div class="am-modal-bd" id="fq_confirm_info"></div>
    <div class="am-modal-footer">
      <span class="am-modal-btn" data-am-modal-confirm>确定</span>
    </div>
  </div>
</div>

<div class="am-modal am-modal-confirm" tabindex="-1" id="fq_true_confirm">
  <div class="am-modal-dialog">
    <div class="am-modal-hd" id="fq_true_confirm_title"></div>
    <div class="am-modal-bd" id="fq_true_confirm_info"></div>
    <div class="am-modal-footer">
		<span class="am-modal-btn" data-am-modal-confirm>确定</span>
		<span class="am-modal-btn" data-am-modal-cancel class="cancel">取消</span>
    </div>
  </div>
</div>
  

<!-- Modal -->

	<div class="am-modal am-modal-no-btn" tabindex="-1" id="doc-modal-1">

  		<div class="am-modal-dialog">

    		<div class="am-modal-hd am-text-left" style="border-bottom:1px solid #ddd;">

    			<div class="am-padding-horizontal-sm">设置会员标签

    				<a href="javascript: void(0)" class="am-close am-close-spin cancel_tag" data-am-modal-close>&times;</a>

    			</div>

    		</div>

    		<div class="am-modal-bd" style="margin-bottom:0;">

    			<ul class="tags_list">

					<volist name="wxgroupList" id="vo">	
    				<li class="am-fl sizeofli am-padding-horizontal-sm">

								<label class="am-checkbox am-text-truncate am-text-left tags_name_list">

	    							<input type="checkbox" name="tag" value="{$vo.wechatgroupid}" data-am-ucheck class="tag_msg" > {$vo.name}
	  							</label>

							</li>
							</volist>
							 
    			</ul>

    			<div class="am-cf"></div>

    			<span class="num_tips am-text-left am-text-danger am-text-sm am-text-left am-padding-horizontal-sm am-margin-top-xs" style="display:block;"></span>

    			<div class="am-padding-horizontal-sm am-margin-top-xs">

    				<a href="javascript:void(0);" id="create" class="am-text-left am-fl am-text-sm">新建标签</a>

    				<div style="display:none;line-height:32px;" id="new_tags_box" class="am-text-left">

	    				<span class="test am-text-left am-fl am-text-sm" style="width:60%;display:inline-block;border:1px solid #e7e7eb;line-height:32px;">

	    					<input type="text" name="tag_info" style="width:79%;border:0;outline:none;height:30px;" id="text" class="am-margin-right-sm am-fl"><span class="text_num">0</span>/12

	    				</span> <a href="javascript:void(0);" class="plus am-margin-horizontal-xs am-text-sm">添加</a>

	    				<a href="javascript:void(0);" class="cancel am-text-sm">取消</a>

    				</div>

    				<div class="am-cf"></div>

    				<span style="display:block;" class="am-text-left am-text-danger am-text-sm danger"></span>

    			</div>

    		</div>

    		<div style="padding:15px 10px;border-top: 1px solid #ddd;">

    			<button type="button" class="am-btn am-btn-success am-text-sm am-padding-horizontal-lg save_tag" data-id>保存</button>

				<button type="button" class="am-btn am-btn-default am-text-sm am-padding-horizontal-lg cancel_tag" data-am-modal-close>取消</button>

    		</div>

  		</div>

	</div>

<!-- Modal -->

<!-- content start -->

	<div class="admin-content">

		<div class="admin-content-body">

			<div class="am-margin-top-sm am-margin-left">

				<strong class="am-text-primary am-text-lg">微信会员</strong> / <small>Wechat members</small>

			</div>

			<div class="am-margin">

				<div class="">

					<div class="form am-margin-bottom" style="display:inline-block;width:100%;">

							<div class="am-inline-block">

								 

							</div>

							<div class="tagHide" style="display:inline-block">

								<select data-am-selected="{maxHeight:300}" class="tags" data-tags=>

									<option value="-1" >会员标签</option>

									<option value="0" >无标签会员</option>
									
									<volist name="wxgroupList" id="vo">	

									<option value="{$vo.wechatgroupid}" <if condition="$vo['wechatgroupid'] eq $tagId"> selected="selected"</if> >{$vo.name}</option> 
									</volist>
								</select>

							</div>

							<span class="am-icon-spinner am-icon-spin am-margin-left-sm selectTip"></span>

						<!--	<button type="button" class="am-btn am-btn-primary am-text-sm am-margin-left-xs get_user">同步微信会员信息<span id="async">（同步中 <span id="plan">0</span> / <span id="total"></span>）</span></button>
-->
							<div class="am-fr am-inline-block"> 

									<div class="am-fl">

										<select data-am-selected id="type" name="type">

											<option value="1" selected>按昵称搜索</option>

											<option value="2" >按UID搜索</option>

										</select>

									</div>

									<div class="am-fl">

										<div class="am-input-group" style="width:276px;margin-left:5px;">

						    				<input type="text" value="" name="search_member" placeholder="会员昵称" class="member_search am-form-field" style="width:222px;height:32px;" onkeydown="if(event.keyCode == 13){search();return;}" />

						    				<span class="am-input-group-btn">

												<button class="am-btn am-btn-default submit" type="button"  style="height:32px;padding-top:5px;"><span class="am-icon-search"></span></button>

											</span>

										</div>

									</div>

							</div>

					</div>

    			</div>

				<div id="tagsTool">

					<div class="am-checkbox-inline" style="margin:0;">

						<label style="margin:0;cursor:pointer;">

							<input type="checkbox" id="selectAll" /> 全选

						</label>

					</div>

					<!--<button type="button" class="am-btn am-btn-default am-text-sm" id="setAll" disabled="disabled">批量设置标签</button>-->

				</div>

				<style>
					
					.active{
						color:rgb(224,24,24);
					}
					.active:hover{
						color:rgb(221,81,76);
					}

				</style>

				<table class="am-table am-table-striped am-table-hover am-text-sm user_list_table" >

					<thead>

						<tr>

							<th>

								&nbsp;

							</th>

							<th>头像</th>

							<th>昵称/OPENID</th> 

							<th>性别</th>

						 

						 

							<th>时间 <!--<a href="/user/index/sort/2.html" class="sorttime "><i class="am-icon-arrow-down"></i></a>--></th>
<th>分组</th>
							 

						<!--	<th class="am-text-center">管理备注</th>-->

							<th>操作</th>

						</tr>

					</thead>

					<tbody id="member_box">

						
							
						 
					<volist name="userList" id="vo">		
							 
								
							<tr>

								<td class="tagNum{$vo.id}">

								   	<input type="checkbox" class="tagsCount" value="1" data-status="1" data-uid="{$vo.id}" />

								</td>

								<td><img src="{$vo.wxheadpic}" style="width:48px;height:48px;"></td>

								<td>

									<span class="am-badge am-badge-success">UID:{$vo.id}</span> {$vo.wxnickname}<br>

									<span style="color: #B0AFAF;">{$vo.wxopenid}</span>

								</td>
 

								<td><if condition="$vo['gender'] eq 1"> 男</if><if condition="$vo['gender'] eq 2"> 女</if><if condition="$vo['gender'] eq 0"> 未知</if> </td>

								 

							 

								<td> {$vo["reg_time"]|date="Y-m-d H:i:s",###}</td>

								 <td>
<div class="tags{$vo.id}">

							<span style="width:120px;" class="am-badge am-badge-secondary">{$vo["groupName"]}	</span>	 	
									</div>

								</td>

								 <!--
								<td class="am-text-center">

									<span class="remark"></span> <a href="javascript:void(0)" class="edit_remark" title="修改备注" data-status="1"><i class="am-icon-edit"></i></a>

									<div class="set_remark">

										<div class="popover am-padding-lg am-text-sm" style="display:none;">

											<h4 style="margin:0;">备注内容</h4>

											<input type="text" class="am-padding-left-sm am-padding-right-lg remark_text" style="height:32px;">

											<span class="tag_tips am-text-danger m-margin-top-sm"></span>

											<div class="am-margin-top-sm">

												<button type="button" class="am-btn am-btn-success am-text-sm am-padding-horizontal-lg remark_submit" data-id="{$vo.wxopenid}" data-subscribe="1">确认</button>

												<button type="button" class="am-btn am-btn-default am-text-sm am-padding-horizontal-lg am-fr tag_cancel">取消</button>

											</div>

											<i class="popover_arrow popover_arrow_out"></i>

											<i class="popover_arrow popover_arrow_in"></i>

										</div>

									</div>

									

								</td>
-->
								<td>

									<div class="am-btn-group">

										<button type="button" class="am-btn am-btn-success am-text-xs get_open" data-id="{$vo.wxopenid}"  data-position="{$vo.id}" data-status = "1" data-black="0" data-tags={$vo.wxgroupid}>设置标签</button>

										<!--
											<button type="button" class="am-btn am-btn-danger am-text-xs set_black" data-id="11" data-position="111" data-status = "1">加入黑名单</button>
										<a href="/user/record/uid/11" target="_blank" class="am-btn am-btn-secondary am-text-xs"">积分记录</a>-->

									</div>

								</td>

							</tr>
							</volist>
							 
					</tbody>

				</table>

				<!--<div class="zone" style="display:none;width:100%;text-align:center;">无会员信息，重新获取<a href="/user/index.html">全部用户</a></div>-->

				<ul class="am-pagination am-pagination-centered am-text-xs" id="page"> {$page}</ul>

			</div>

		</div>

		<footer class="admin-content-footer">
	<hr>
	<p class="am-padding-left">淘优惠 微信淘客系统 版权所有  Copyright © 2004-2016 爱淘客(www.itaoke.org).All Rights Reserved</p>
</footer>

	</div>

<!-- content end -->

	

</div>

<div class="am-modal am-modal-prompt" tabindex="-1" id="my-prompt-2">

	<div class="am-modal-dialog">

		<div class="am-modal-bd am-cf" style="padding:20px 15px;">

			<div class="am-fl" style="padding:0;width:20%;height:100%;margin-right:2%">

				<select id="scoreType" style="padding:.5rem;width:100%;border:1px solid #ccc;height:35px;" class="am-text-sm">

					<option value="1" selected>奖励</option>

  					<option value="0">扣除</option>

				</select>

			</div>

			<input type="text" class="am-form-field am-fl am-text-sm" id="amend_score" placeholder="积分数量" style="width:78%;height:35px;" />

			<div class="am-cf"></div>

			<div class="textareaBox am-margin-top-sm" style="border:1px solid #ccc;">

				<textarea class="am-padding-xs" id="amend_score_reason" style="width:100%;height:100px;border:0;" placeholder="请输入原因"></textarea>

				<div style="height:30px;line-height:30px; border-top:1px solid #ccc;">

					<p class="am-fr am-padding-horizontal-sm am-text-sm reason" style="color:#8d8d8d;margin:0;display:block">还可以输入 <em class="limit">50</em> 字</p>

					<p class="am-fr am-padding-horizontal-sm am-text-sm reasonBreak" style="color:#8d8d8d;margin:0;display:none;">已超出 <em class="limit limitColor"></em> 字</p>

				</div>

			</div>

		</div>

		<div class="am-modal-footer">

			<span class="am-modal-btn" data-am-modal-confirm>提交</span>

			<span class="am-modal-btn" data-am-modal-cancel>取消</span>

		</div>

	</div>

</div>

<div class="am-hide"> </div>					
</html>

<script>

	function strlength(str){

    	var len = 0;

    	for (var i=0; i<str.length; i++) { 

     		var c = str.charCodeAt(i); 

     		if ((c >= 0x0001 && c <= 0x007e) || (0xff60<=c && c<=0xff9f)) { 

       			len++; 

     		}else { 

      			len+=2; 

     		} 

    	} 

    	return len;

	}

	function search(){

		$('.submit').click();

	}


	$(function(){

		//全选

		$('#tagsTool').on('click','#selectAll',function(){

			var checkLen = $('.tagsCount').length;

			var j = 0;

			for(var i = 0;i < checkLen;i++){

				if($('.tagsCount').eq(i).attr('data-status') == 1){

					$('.tagsCount').eq(i).prop('checked',$(this).prop('checked'));

					j++;

				}

			}

			if($(this).prop('checked') == true && j > 0){

				$('#setAll').prop('disabled',false);

			}else{

				$('#setAll').prop('disabled',true);

			}

			

		});



		//单选

		$('.user_list_table').on('click','.tagsCount',function(){

			var status = $(this).attr('data-status');

			if(status == 0){

				$('#fq_alert').modal({});

				$('#fq_alert_info').text('未关注状态下无法设置标签');

				$(this).prop('checked',false);

				return;

			}

			var tagsLen = 0;

			var len = $('.tagsCount').length;

			for(var i = 0 , j = 0 ; i < len ; i++ ){

				if($('.tagsCount').eq(i).prop('checked') == true){

					if($('.tagsCount').eq(i).val() > tagsLen ){

						tagsLen = $('.tagsCount').eq(i).val();

					}

					j++;

				}

			}

			if(j > 0){

				$('#setAll').prop('disabled',false).attr('data-num',tagsLen);

			}else{

				$('#setAll').prop('disabled',true).attr('data-num','');

			}

		});



		//批量设置标签

		$('#setAll').click(function(){

			$('.save_tag').removeClass('in');

			$('.tag_msg').prop('checked',false);

			var checkLen = $('.tagsCount').length;

			var len = 0;

			for(var i = 0; i < checkLen; i++){

				if($('.tagsCount').eq(i).attr('data-status') == 1 && $('.tagsCount').eq(i).prop('checked') == true){

					if($('.tagsCount').eq(i).val() > len){

						len = $('.tagsCount').eq(i).val();

					}

				}

			}

			$(this).attr('data-num',len);

			$('#doc-modal-1').modal();

		});







		//搜索类型

		$('#type').change(function(){

			var type = $(this).val();

			if(type == 1){

				$('.member_search').attr('placeholder','会员昵称');

			}

			if(type == 2){

				$('.member_search').attr('placeholder','会员UID');

			}

		});



		//搜索

		$('.submit').click(function(){

			var type = $('#type').val();

			var search = $.trim($('.member_search').val());



			if(search == ''){

				$('#fq_alert').modal({});

				$('#fq_alert_info').text('搜索内容不能为空');

				return false;

			}

			window.location.href = 'index.php?m=Admin&c=Weixin&a=wxuser&search_member='+search+'&type='+type;

			

		});

		

		$('.user_list_table').on('click','.popover',function(event){

			event.stopPropagation();

		});





		$('.user_list_table').on('click','.tag_cancel',function(){

			$('.popover,.tag_tips').hide();

		});



		$(document).on('click',function(){

			$('.popover,.tag_tips').hide();

		})



		//修改备注名称

		$('#member_box').on('click','.edit_remark',function(event){



			$('.popover').hide();

			var remark = $(this).siblings('.remark').text();

			var setBox = $(this).siblings('.set_remark').children('.popover');

			setBox.show();

			if($(this).attr('data-status') == 0){

				$(this).siblings('.set_remark').find('.tag_tips').show().text('未关注状态下无法设置备注');

				return false;

			}



			setBox.children('.remark_text').val(remark).focus().select();

			event.stopPropagation();

		});

		//确认

		$('#member_box').on('click','.remark_submit',function(){

			



			var status = $(this).attr('data-subscribe');

			if(status == 0){

				$(this).parent().siblings('.tag_tips').show().text('未关注状态下无法设置备注');

				return false;

			}



			$('.popover').hide();

			var old_remark_box = $(this).parent().parent('.popover').parent('.set_remark').siblings('.remark');

			var old_remark = old_remark_box.text();

			var new_remark = $(this).parent().siblings('.remark_text').val();

			if(old_remark == $.trim(new_remark)){

				return false;

			}

			var openid = $(this).attr('data-id');

			old_remark_box.html('<i class="am-icon-spinner am-icon-spin"></i> 设置中');

			$.ajax({

				type:'post',

				url:'/user/set_remark.html',

				data:{"remark":new_remark,"openid":openid},

				daatType:'json',

				success:function(){

					old_remark_box.text(new_remark);

				}



			});

			

		});



		$('#create').click(function(){

			$('#new_tags_box').show();

			$('#text').focus();

			$(this).hide();

		});



		$('#text').keyup(function(){

			var str = $(this).val();

			var len = strlength(str);

			$('.text_num').text(len);

			if(len>12){

				$('.test').css('border-color','rgb(221, 81, 76)');

				$('.danger').text('长度不可超过6个汉字或12个字符').show();

			}else{

				$('.test').css('border-color','#e7e7eb');

				$('.danger').hide();

			}



		});



		$('#member_box').on('click','.cancel',function(){

			$('#new_tags_box,.danger').hide();

			$('#text').val('');

			$('#create').show();

			$('.text_num').text(0);

			$('.test').css('border-color','#e7e7eb');

		});



		//添加分组

		$('.plus').click(function(){

			var tag = $.trim($('#text').val());



			if(tag == ''){

				return false;

			}



			var len = strlength(tag);

			if(len>12){

				$('.danger').text('长度不可超过6个汉字或12个字符').show();

				$('.test').css('border-color','rgb(221, 81, 76)');

				return false;

			}

			var list = $('.tags_name_list');

			var list_len = list.length;

			for(var i=0;i<list_len;i++){

				if(tag == $.trim(list.eq(i).text())){

					$('.danger').text('已存在相同分组').show();

					return false;

				}

			}



			$.ajax({

				type:'post',

				url:'/tags/new_tag.html',

				data:{"name":tag},

				dataType:'json',

				success:function(data){

					if(data.status == 1){

						$('.tags_list').append('<li class="am-fl sizeofli am-padding-horizontal-sm"><label class="am-checkbox am-text-truncate am-text-left tags_name_list"><input type="checkbox" name="tag" value="'+data.id+'" data-am-ucheck class="tag_msg">'+tag+'</label></li>');

						$('.tags').append('<option value="'+data.id+'">'+tag+'</option>');

						$('#new_tags_box').hide();

						$('#text').val('');

						$('#create').show();

						$('.text_num').text(0);

						$('.test').css('border-color','#e7e7eb');

						$('input[type=checkbox][value='+data.id+']').uCheck();

					}else{

						$('.danger').text(data.info).show();

					}

				}

			});	

		});

		//取消添加分组

		$('.cancel').click(function(){

			$('#create').show();

			$('#new_tags_box,.danger').hide();

			$('#text').val('');

			$('.text_num').text(0);

		});



		//获取openid

		$('#member_box').on('click','.get_open',function(){

			var id = $(this).attr('data-id');

			var tags = $(this).attr('data-tags');

			var uid = $(this).attr('data-position');

			var subscribe = $(this).attr('data-status');

			//转为数组

			var tags_list = tags.split('|');

			if(subscribe == 0){

				$('.danger').text('未关注状态下无法设置标签').show();

			}else{

				$('.danger').text('').hide();

			}

			$('input[name=tag]').prop('checked',false);



			var len = tags_list.length;

			for(var i=0;i<len;i++){

				

				if(tags_list[i] != ""){

					$('input[name=tag][value='+tags_list[i]+']').prop('checked',true);

				}

			}

			$('#doc-modal-1').modal();

			$('.save_tag').attr('data-tags',tags).attr('data-id',id).attr('data-position',uid).attr('data-status',subscribe).addClass('in');

		});



		//取消

		$('.cancel_tag').click(function(){

			$('.tag_msg').prop('checked',false);

			$('.danger').text('').hide();

			$('.test').css('border-color','rgb(231, 231, 235)');

			$('#text').val('');

			$('.num_tips').text('');

			$('.text_num').text(0);

			$('#new_tags_box').hide();

			$('#create').show();

			$('#setAll').attr('data-num','');

		});



		//判断所选标签个数

		$('.tags_list').on('click','.tag_msg',function(){

			var tag_msg = $('.tag_msg');

			var len = tag_msg.length;

			if($('.save_tag').hasClass('in')){

				for(var i = 0 , j=0 ; i<len ; i++){

					if(tag_msg.eq(i).prop('checked') == true){

						j++;

					}

				}

				if(j>1){

					$(this).prop('checked',false);

					$('.num_tips').text('最多只可设置1个标签');

					return false;

				}else{

					$('.num_tips').text('');

				}

			}else{

				var num = $('#setAll').attr('data-num');

				for(var i = 0 , j=0 ; i<len ; i++){

					if(tag_msg.eq(i).prop('checked') == true){

						num++;

					}

				}

				if(num > 1){

					$(this).prop('checked',false);

					$('.num_tips').text('最多只可设置1个标签');

					return false;

				}else{

					$('.num_tips').text('');

				}

			}

		});



		//为用户设置标签

		$('.save_tag').click(function(){

			if($(this).hasClass('in')){

				setOneUser($(this));

			}else{

				setAllUser($(this));

			}

		});



		//---------------------------------->方法

		//为单个用户设置标签

		function setOneUser(obj){

			$('#doc-modal-1').modal('close');

			var subscribe = obj.attr('data-status');

			if(subscribe == 0){

				return false;

			}

			var tags_choose = $('.tag_msg');

			var len = tags_choose.length;

			

			var arr = new Array(); 
			for(var i = 0,j=0; i< len ; i++){

				if(tags_choose.eq(i).prop('checked') == true){

					arr[j] = tags_choose.eq(i).val(); 
					j++;

				}

			}

			if(arr.length>1){

				return false;

			}

			var tag_backup = obj.attr('data-tags');

			var id = obj.attr('data-id');

			var uid = obj.attr('data-position');

			



			if(!tag_backup && arr.length == 0){

				return false;

			}



			if(arr.join('|') == tag_backup){

				return false;

			}



			$('.get_open[data-position='+uid+']').html('<i class="am-icon-spinner am-icon-spin"></i> 设置中').attr('disabled',true);

			$.ajax({

				data:{"openid":id,"tags":arr,"tag_backup":tag_backup},

				dateType:'json',

				url:'index.php?m=Admin&c=Weixin&a=wxusertag',

				type:'post',

				success:function(data){
					 
					 
					if(data.tags){

						var tag_len = data.tags.length,html='';

						var tag_arr = new Array();

						for(var i=0 ; i<tag_len; i++){

							html += '<span style="width:120px;" class="am-badge am-badge-secondary">'+data['tags'][i]['name']+'</span><br>';

							tag_arr[i] = data['tags'][i]['id'];

						}

						$('.tags'+uid).html(html);

						$('.tagNum'+uid).find('input').val(tag_len);

						var tag = tag_arr.join("|");

						$('.get_open[data-position='+uid+']').attr('data-tags',tag).text('设置标签').attr('disabled',false);

					}else{

						$('.tags'+uid).html('');

						$('.tagNum'+uid).find('input').val(0);

						$('.get_open[data-position='+uid+']').attr('data-tags','').text('设置标签').attr('disabled',false);

					} 

				},

				complete:function(XMLHttpRequest,status){

					if(XMLHttpRequest.status != 200){

						$('#fq_alert').modal({});

						$('#fq_alert_info').text('网络连接错误，请稍后再试');

						$('.get_open[data-position='+uid+']').attr('data-tags',tag_backup).text('设置标签').attr('disabled',false);

					}

				}

			});

		}



		//批量为用户设置标签

		function setAllUser(){

			$('#doc-modal-1').modal('close');

			//所选标签

			var tags_choose = $('.tag_msg');

			var len = tags_choose.length;

			var arr = new Array();

			for(var i = 0,j=0; i< len ; i++){

				if(tags_choose.eq(i).prop('checked') == true){

					arr[j] = tags_choose.eq(i).val();

					j++;

				}

			}

			if(arr.length>3){

				return;

			}

			if(arr.length == 0){

				return;

			}

			//所选会员

			var tagsCount = $('.tagsCount');

			var uidLen = tagsCount.length;



			var uidArr = new Array();

			for(var a = 0,b=0; a< uidLen ; a++){

				if(tagsCount.eq(a).prop('checked') == true && tagsCount.eq(a).attr('data-status') == 1){

					uidArr[b] = tagsCount.eq(a).attr('data-uid');

					b++;

				}

			}

			if(uidArr.length == 0){

				return;

			}

			$('#setAll').html('<i class="am-icon-spinner am-icon-spin"></i> 设置中').attr('disabled',true);

			$.ajax({

				url:'/user/batchtags.html',

				type:'post',

				data:{"tags":arr,"uid":uidArr},

				dataType:'json',

				success:function(res){

					window.location.reload();

				},

				complete:function(XMLHttpRequest,status){

					if(status == 'timeout'){

						$('#fq_alert_info').text('操作超时，请稍后再试');

					}else if(XMLHttpRequest.status != 200){

						$('#fq_alert_info').text('网络连接错误，请稍后再试');

					}else{

						$('#fq_alert_info').text('设置成功');

					}

					$('#fq_alert').modal({});

					$('#setAll').text('批量设置标签').attr('disabled',false);

				}

			});



		}





		//处理时间戳

		function get_time(time){

			var timeDate = new Date(time*1000);

			var year = timeDate.getFullYear();

			var month = timeDate.getMonth()+1;

			var day = timeDate.getDate();

			var hour = timeDate.getHours();

			var minute = timeDate.getMinutes();

			var second = timeDate.getSeconds();



			if(month<10)

				month = '0'+month;

			if(day<10)

				day = '0'+day;

			if(hour<10)

				hour = '0'+hour;

			if(minute<10)

				minute = '0'+minute;

			if(second<10)

				second = '0'+second;



			var date = year+'.'+month+'.'+day+' '+hour+':'+minute+':'+second;

			return date;



		}



		function condition(status,tag){



			$('.selectTip').show();

			if(status == 0){

				$('.tagHide').css('display','none');

				tag = -1;



			}else{

				$('.tagHide').css('display','inline-block');

			}

			var sort;

			if($('.sorttime').hasClass('active')){

				sort = 2;

			}else if($('.sortscore').hasClass('active')){

				sort = 1;

			}else{

				sort = 0;

			}

			location.href='index.php?m=Admin&c=Weixin&a=wxuser&tag='+tag;
			return;
			$.ajax({

				type:'get',

				dataType:'json',

				url:'index.php?m=Admin&c=Weixin&a=wxuserjson',

				data:{"tag":tag,"status":status,"sort":sort},

				success:function(data){

					var len = data.user_list.length;

					if(len>0){

						var tags_list_len = data.tags_list.length;



						var html;

						var subscribe,sex,tags_list,ip,ip_address,remark,black,blackBtn;

						for(var i = 0 ; i<len ;i++){

							var tags_html = '';

							tags_list = data['user_list'][i]['tags'];

							if(tags_list){

								var tags_arr = tags_list.split('|');

								var tags_len = tags_arr.length;

								for(var j=0;j<tags_len;j++){

									for(var k=0;k<tags_list_len;k++){

										if(tags_arr[j] == data['tags_list'][k]['id']){

											tags_html +='<span style="width:120px;" class="am-badge am-badge-secondary">'+data['tags_list'][k]['name']+'</span><br>';

										}

									}

								}



							}else{

								tags_html = '';

							}

							



							if(data['user_list'][i]['subscribe'] == 0){

								subscribe = '未关注';

							}else{

								subscribe = '已关注';

							}



							if(!data['user_list'][i]['ip']){

								ip=' ';

							}else{

								ip=data['user_list'][i]['ip']+'<br>';

							}



							if(!data['user_list'][i]['ip_address']){

								ip_address=' ';

							}else{

								ip_address=data['user_list'][i]['ip_address'];

							}



							if(data['user_list'][i]['sex'] == 1){

								sex = '男';

							}else if(data['user_list'][i]['sex'] == 0){

								sex = '女';

							}else{

								sex = '未知';

							}



							if(!data['user_list'][i]['remark']){

								remark='';

							}else{

								remark=data['user_list'][i]['remark'];

							}



							if(data['user_list'][i]['black'] == 0){

								black = '';

								blackBtn = '<button type="button" class="am-btn am-btn-danger am-text-xs set_black" data-id="'+data['user_list'][i]['openid']+'"  data-position="'+data['user_list'][i]['uid']+'" data-status = "'+data['user_list'][i]['subscribe']+'">加入黑名单</button>'

							}else{

								black = '<span style="width:120px;" class="am-badge am-badge-warning am-radius">黑名单</span>';

								blackBtn = '<button type="button" class="am-btn am-btn-danger am-text-xs out_black" data-id="'+data['user_list'][i]['openid']+'"  data-position="'+data['user_list'][i]['uid']+'" data-status = "'+data['user_list'][i]['subscribe']+'">移出黑名单</button>'

							}





							html +='<tr><td class="tagNum'+data['user_list'][i]['uid']+'"><input type="checkbox" class="tagsCount" value="'+tags_len+'" data-status="'+data['user_list'][i]['subscribe']+'" data-uid="'+data['user_list'][i]['uid']+'" /></td><td><img src="'+data['user_list'][i]['headimgurl']+'" style="width:48px;height:48px;"></td><td><span class="am-badge am-badge-success">UID:'+data['user_list'][i]['uid']+'</span> '+data['user_list'][i]['nickname']+'<br><span style="color: #B0AFAF;">'+data['user_list'][i]['openid']+'</span></td><td>'+subscribe+'</td><td>'+sex+'</td><td>'+ip+ip_address+'</td><td class="scoreBox"><span class="tipScore">'+data['user_list'][i]['score']+'</span>&nbsp;<a data-score="'+data['user_list'][i]['score']+'" data-uid="'+data['user_list'][i]['uid']+'" href="javascript:void(0);" class="am-icon-edit changeScore"  title="积分修改"></a></td><td>'+get_time(data['user_list'][i]['update_time'])+'</td><td class="am-text-center"><div class="tags'+data['user_list'][i]['uid']+'">'+tags_html+'</div><div class="black'+data['user_list'][i]['uid']+'">'+black+'</div></td><td class="am-text-center"><span class="remark">'+remark+'</span> <a href="javascript:void(0)" class="edit_remark" title="修改备注" data-status="'+data['user_list'][i]['subscribe']+'"><i class="am-icon-edit"></i></a><div class="set_remark"><div class="popover am-padding-lg am-text-sm" style="display:none;"><h4 style="margin:0;">备注内容</h4><input type="text" class="am-padding-left-sm am-padding-right-lg remark_text" style="height:32px;"><span class="tag_tips am-text-danger m-margin-top-sm"></span><div class="am-margin-top-sm"><button type="button" class="am-btn am-btn-success am-text-sm am-padding-horizontal-lg remark_submit" data-id="'+data['user_list'][i]['openid']+'" data-subscribe="'+data['user_list'][i]['subscribe']+'">确认</button><button type="button" class="am-btn am-btn-default am-text-sm am-padding-horizontal-lg am-fr tag_cancel">取消</button></div><i class="popover_arrow popover_arrow_out"></i><i class="popover_arrow popover_arrow_in"></i></div></div></td><td><div class="am-btn-group"><button type="button" class="am-btn am-btn-success am-text-xs get_open" data-id="'+data['user_list'][i]['openid']+'"  data-position="'+data['user_list'][i]['uid']+'" data-status = "'+data['user_list'][i]['subscribe']+'" data-tags="'+data['user_list'][i]['tags']+'">设置标签</button>'+blackBtn+'<a href="/User/record/uid/'+data['user_list'][i]['uid']+'" target="_blank" class="am-btn am-btn-secondary am-text-xs"">积分记录</a></div></td></tr>'

						}

						$('#member_box').html(html);

						$('.zone').hide();

					}else{

						$('#member_box').html('');

						$('.zone').show();

					}

					$('#page').html(data.Page);

 
					$('.selectTip').hide();

				}

			});

		}



		function black(obj,sort){

			var id = obj.attr('data-id');

			var uid = obj.attr('data-position');

			var status = obj.attr('data-status');

			if(status == 0){

				$('#fq_alert').modal({});

				$('#fq_alert_info').text('未关注状态下无法移入或移出黑名单');

				return false;

			}else{

				$('.danger').hide();

			}

			obj.html('<i class="am-icon-spinner am-icon-spin"></i> 设置中').attr('disabled',true);

			$.ajax({

				data:{"openid":id,"sort":sort},

				dataType:'json',

				type:'post',

				url:'/user/setblack.html',

				success:function(data){

					if(sort == 1){

						if(data.status == 1){

							$('.black'+uid).html('<span style="width:120px;" class="am-badge am-badge-warning am-radius">黑名单</span>');

							obj.replaceWith('<button type="button" class="am-btn am-btn-danger am-text-xs out_black" data-id="'+id+'" data-position="'+uid+'" data-status = "'+status+'">移出黑名单</button>');

						}else{

							obj.text('加入黑名单').attr('disabled',false);

							$('#fq_alert').modal({});

							$('#fq_alert_info').text(data.info);

						}

						

					}else{

						if(data.status ==1){

							$('.black'+uid).html('');

							obj.replaceWith('<button type="button" class="am-btn am-btn-danger am-text-xs set_black" data-id="'+id+'" data-position="'+uid+'" data-status = "'+status+'">加入黑名单</button>');

						}else{

							obj.text('移出黑名单').attr('disabled',false);

							$('#fq_alert').modal({});

							$('#fq_alert_info').text(data.info);

						}

						

					}

					

				}

			})

		}





		function getUser(arr,i,time){

			var start = i*100;

			var end = (i+1)*100;

			var box = arr.slice(start,end);

			$.ajax({

				data:{"id":box},

				type:'post',

				dataType:'json',

				url:'/user/saveuser.html',

				success:function(res){

					if(res.status == 1){

						var a = i+1;

						$('#plan').text(a);

						if(time > a){

							getUser(arr,a,time);

						}else{

							$('#fq_alert_info').text('同步完成');

							$('#fq_alert').modal({});

							$('.get_user').attr('disabled',false);

							$('#async').hide();

							$('#plan').text(0);

							$('#total').text('');

							window.location.reload();

						}

					}

				}

			});

		}



		//------->function end



		//关注状态查询

		$('.subscribe').change(function(){

			var backup = $(this).attr('data-selected');

			var status = $(this).val();

			if(backup == status){

				return false;

			}

	

			$(this).attr('data-selected',status);

			var tag = $('.tags').val();

			condition(status,tag);



		});

		//分组状态查询

		$('.tags').change(function(){

			var backup = $(this).attr('data-tags');

			var tag = $(this).val();

			if(backup == tag){

				return false;

			}

			

			$(this).attr('data-tags',tag);

			var status = $('.subscribe').val();

			

			condition(status,tag);



		});

		//黑名单设置

		$('#member_box').on('click','.set_black',function(){

			black($(this),1);

		});

		$('#member_box').on('click','.out_black',function(){

			black($(this),0);

		});



		

		//手动扣除、奖励积分

		$('#member_box').on('click','.changeScore',function(){

			$('#scoreType option').prop('selected',false);

			$('#scoreType option[value=1]').prop('selected',true);

		 	$('#amend_score_reason,#amend_score').val('');

		 	$('.reason').show();

		 	$('.reasonBreak').hide();

		 	$('.reason .limit').text(50);

		 	$('.reasonBreak .limit').text('');

		 	$('#my-prompt-2').modal({

		 		relatedTarget:this,

		 		onConfirm:function(){

		 			var type = $('#scoreType').val();

		 			var score = $.trim($('#amend_score').val());

		 			var reason = $('#amend_score_reason').val();

		 			var nowScore = $(this.relatedTarget).attr('data-score');

		 			//验证原因长度

		 			if(reason.length > 50){

		 				$('#fq_alert').modal({});

		 				$('#fq_alert_info').text('原因字数不可超过50字');

		 				return;

		 			}

		 			//验证输入积分

					if(score == ''){

						$('#fq_alert').modal({});

		 				$('#fq_alert_info').text('奖励或扣除的积分为空');

		 				return;

					}



					if(score.match(/^\d{1,}$/) == null || score < 0){

						$('#fq_alert').modal({});

		 				$('#fq_alert_info').text('奖励或扣除的积分只能为大于或等于0的整数');

		 				return;

					}

					//会员uid

					var uid = $(this.relatedTarget).attr('data-uid');

					var scoreBox = $(this.relatedTarget).parent('.scoreBox');

					scoreBox.html('&nbsp;修改中 <i class="am-icon-circle-o-notch am-icon-spin"></i>');

					$(this.relatedTarget).prop('disabled',true);



					$.ajax({

						url:"/user/amendscore.html",

						type:'post',

						dataType:'json',

						data:{"uid":uid,"score":score,"type":type,"reason":reason},

						success:function(res){

							if(res.status == 0){

								$('#fq_alert').modal({});

		 						$('#fq_alert_info').text(res.info);

		 						scoreBox.html('<span class="tipScore">'+nowScore+'</span>&nbsp;<a data-score="'+nowScore+'" data-uid="'+uid+'" href="javascript:void(0);" class="am-icon-edit changeScore"  title="积分修改"></a>');

							}else if(res.status == 1){

		 						if(type == 1){

		 							var change = parseInt(nowScore) + parseInt(score);

		 						}else if(type == 0){

		 							var change = parseInt(nowScore) - parseInt(score);

		 						}

		 						scoreBox.html('<span class="tipScore">'+change+'</span>&nbsp;<a data-score="'+change+'" data-uid="'+uid+'" href="javascript:void(0);" class="am-icon-edit changeScore"  title="积分修改"></a>');

							}

						},

						complete:function(XMLHttpRequest,status){

							if(XMLHttpRequest.status != 200){

								$('#fq_alert').modal({});

		 						$('#fq_alert_info').text('修改失败，请稍后再试');

		 						scoreBox.html('<span class="tipScore">'+nowScore+'</span>&nbsp;<a data-score="'+nowScore+'" data-uid="'+uid+'" href="javascript:void(0);" class="am-icon-edit changeScore"  title="积分修改"></a>');

							}

						}

					});



		 		},

		 		onCancel:function(){

		 			$('#scoreType option').prop('selected',false);

					$('#scoreType option[value=1]').prop('selected',true);

		 			$('#amend_score_reason,#amend_score').val('');

		 			$('.reason').show();

				 	$('.reasonBreak').hide();

				 	$('.reason .limit').text(50);

				 	$('.reasonBreak .limit').text('');



		 		}

		 	});

		});



		//字数限制

		$('#amend_score_reason').keyup(function(){

			var reasonLen = $(this).val().length;

			$('.reason,.reasonBreak').hide();

			if(reasonLen <= 50){

				$('.reason').show();

				$('.reason .limit').text(50-parseInt(reasonLen));

			}

			if(reasonLen > 50){

				$('.reasonBreak').show();

				$('.reasonBreak .limit').text(parseInt(reasonLen)-50);

			}

		});





		$('.get_user').click(function(){

			$(this).attr('disabled',true);

			$.ajax({

				url:'/user/getlist.html',

				type:'post',

				success:function(res){

					if(res.status == 1){

						$('#fq_alert').modal({});

						$('#fq_alert_info').text('同步中，请勿关闭本页面,否则无法获取完整数据');

						var len = res.list.length;

						

						if(len == 0){

							$('#fq_alert').modal({});

							$('#fq_alert_info').text('无用户数据');

							$('.get_user').attr('disabled',false);

							return false;

						}



						var time = Math.ceil(len/100);

						var i=0;

						$('#async').show();

						$('#plan').text(i);

						$('#total').text(time);

						getUser(res.list,i,time);

					}else{

						$('#fq_alert').modal({});

						$('#fq_alert_info').text('系统繁忙，请稍后再试');

					}

				}

			});

			

		});



	});

</script>